<?php
namespace Modules\Box\Http\Controllers\Client\V1;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;

use \Modules\Box\Entities\Box;
use \Modules\Box\Entities\BoxRecord;

use Validator;
use ThrowException;
use DB;
use Setting;


// 盲盒
class RecordController extends Controller
{
    // 获取开盒记录
    public function index(Request $req, $uuid)
    {
        $rule = [
        ];
        Validator::make($req->all(), $rule)->fails() && ThrowException::BadRequest(); 

        $box = Box::getEntity([
            'uuid' => $uuid
        ]);

        $options = $req->all();

        $builder = BoxRecord::where('node_id', $box->id);

        $setting = @Setting::get('sys_box_record_list') ?: [];

        if (@$setting['level_ids']) {
            $builder = $builder->whereIn('level', $setting['level_ids']);
        }
        // $options['builder'] = $box->skus()->onStock();
        $options['builder'] = $builder;

        // $options['only'] = [
        //     'title',
        //     'id',
        //     'uuid',
        //     'money_price',
        //     'score_price',
        //     'number',
        //     'thumb',
        //     'stock',
        //     'is_hidden_sku',
        //     'odds'
        // ];

        $list = BoxRecord::getList($options);

        return $list->generateListResponse();
    }
}
